package tq.com.tqteacher.activity.newPublish;

import android.graphics.Color;
import android.os.Bundle;
import android.print.PrinterId;
import android.support.annotation.Nullable;
import android.view.View;

import com.githang.statusbar.StatusBarCompat;

import java.util.ArrayList;

import tq.com.systools.system.AlertDialogHelper;
import tq.com.tqcom.base.BaseActivity;
import tq.com.tqcom.net.INetCallback;
import tq.com.tqcom.net.TQNetResult;
import tq.com.tqcom.util.TQEventBus;
import tq.com.tqcom.util.TQSystemDefine;
import tq.com.tqcom.view.TQHeader5View;
import tq.com.tqteacher.R;
import tq.com.tqteacher.activity.TQNewPublishFXJActivity;
import tq.com.tqteacher.model.TQLogin;
import tq.com.tqteacher.model.TQPublishType;
import tq.com.tqteacher.model.TQTWDYPublishModel;
import tq.com.tqteacher.view.TQBasePublishInfoView;
import tq.com.tqteacher.view.TQHeader3ViewHold;

public class TQTWDYPublishActivity extends BaseActivity {
    private TQHeader5View mHeader5View;

    private TQBasePublishInfoView mBasePublishInfoView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setStatusBar();
        setContentView(R.layout.activity_twdy_publish_layout);

        mHeader5View = findViewById(R.id.title);
        mHeader5View.getTitleView().setText("提问&群答疑");
        mHeader5View.getBackIcon().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TQTWDYPublishActivity.this.finish();
            }
        });
        findViewById(R.id.next).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                next();
            }
        });

        mBasePublishInfoView = findViewById(R.id.baseInfo);

        TQTWDYPublishModel lModel = null;
        if(TQPublishType.getSharePublishItem() != null && TQPublishType.getSharePublishItem() instanceof TQTWDYPublishModel){
            lModel = (TQTWDYPublishModel) TQPublishType.getSharePublishItem();
        }

        TQBasePublishInfoView.GradData lGradData = new TQBasePublishInfoView.GradData(TQLogin.getCurrent().getUserInfo().getGrade(),
                TQSystemDefine.gradeName(TQLogin.getCurrent().getUserInfo().getGrade()));
        ArrayList<TQBasePublishInfoView.GradData> lGradData1 = new ArrayList<>();
        lGradData1.add(lGradData);
        mBasePublishInfoView.setGradData(lGradData1);

        if(lModel != null && lModel.isModify()){
            mBasePublishInfoView.setPublishContent(lModel);
        }
    }


    private void next(){
        if(!mBasePublishInfoView.checkValid()){
            return;
        }

        TQPublishType.setSharePublishItemBaseInfo(mBasePublishInfoView.title(), mBasePublishInfoView.desc(),
                mBasePublishInfoView.getCurrentGrade().getId());
        if(TQPublishType.getSharePublishItem().isModify()){
            TQPublishType.getSharePublishItem().onModifyBaseInfo(new INetCallback() {
                @Override
                public void result(TQNetResult pNetResult) {
                    if(!pNetResult.isSuccess()){
                        AlertDialogHelper.show(TQTWDYPublishActivity.this, pNetResult.getErrMsg());
                        return;
                    }

                    TQEventBus.post(new TQEventBus.TQEventMessage(TQEventBus.TQEventMessage.Opertor.modify, null));
                    TQTWDYPublishActivity.this.finish();
                }
            });
        }else{
            TQPublishType.showPublishNextStep(this);
        }
    }
}
